<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>

</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('AdminOrder/courseList')}">课程列表</a></li>
        <li class="active"><a href="#">录入订单</a></li>
    </ul>    
        <div class="row">
            <div class="col-md-5">
                <table class="table table-bordered">
                        <tr>
                                <th width="150">订单号</th>
                                <td>
                                    {$orderData.order_no}
                                </td>
                            </tr>   
                    <tr>
                        <th width="150">课程名称</th>
                        <td>
                            {$courseData.title}
                        </td>
                    </tr>                   
                    <tr>
                        <th >班别</th>
                        <td>
                            {$courseData.school_class.name}
                        </td>
                    </tr>
                    <tr>
                        <th >教师</th>
                        <td>
                            {$courseData.school_teacher.name}
                        </td>
                    </tr>
                    <tr>
                        <th>课室</th>
                        <td>
                            {$courseData.classroom}               
                        </td>
                    </tr>                                   
                    <tr>
                        <th>价格</th>
                        <td>
                            {$courseData.price}               
                        </td>
                    </tr>  
                    <tr>
                        <th>开班时间</th>
                        <td>
                            {$courseData.open_time}                 
                        </td>
                    </tr>
                    <tr>
                        <th>报名时间</th>
                        <td>
                            {$courseData.signup_time}                          
                        </td>
                    </tr>
                    <tr>
                        <th>上课时间</th>
                        <td>
                            {$courseData.class_time}                          
                        </td>
                    </tr>
                    <tr>
                        <th>报名截止时间</th>
                        <td>
                            {$courseData.cutoff_time}                       
                        </td>
                    </tr>                                          
                </table>
                <hook name="portal_admin_article_edit_view_main"/>
                
            </div>
            <div class="col-md-7">
                <table class="table table-bordered">
                    <tr id="code">                        
                        <th width="150">授权码</th>
                        <td>
                            <input class="form-control" type="text" name="auth_code" id="auth_code" 
                            autofocus="autofocus">   
                        </td>
                    </tr>      
                    <tr >         
                            <th width="150">支付状态</th>         
                            <td width="150"><div id="pay_status">等待扫码支付。。。</div></td>                            
                    </tr>
                </table>

                <hook name="portal_admin_article_edit_view_right_sidebar"/>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">                          
                        <input id="order_id" type="hidden" name="order_id" value="{$orderData['id']}">                        
                        <a class="btn btn-default" href="{:url('AdminOrder/index')}">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>
        </div>
    
</div>
<style>
    .seats{
        margin:0 auto;
        width:400px;  
        margin-top:5px;       
        display: flex;
        flex-direction: row;
        flex-wrap:wrap;
        justify-content:flex-start;  
        overflow: hidden;
        white-space: nowrap;       
    }
    .seats .item{  
        margin-top:5px;
    }
    .seats .seat-item{
        width:40px;
        height:40px;
        margin:1px;
    }
    .m-right{
  margin-right:20px;
}
.selected{
  background-color: #6ce653;
  border-radius: 13px;
}
.disabled{
  background-color: #c5c8ce;
  border-radius: 13px;
}
</style>

<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
   $(function(){      
       var interval = setInterval(function(){          
        if($('#auth_code').val()){
            clearInterval(interval);
            setTimeout(function(){
                $.ajax({
                    url: '/school/admin_order/ajax_pay',          
                    data: {
                        id: $('#order_id').val(),
                        auth_code: $('#auth_code').val()
                    },  
                    success: function(data){  
                        data = JSON.parse(data)                          
                        if(data['return_code']=="SUCCESS" && data['result_code']=="SUCCESS"){
                            //支付成功
                            $('#code').hide();
                            $("#pay_status").html("支付成功！")                             
                        }else if(data['return_code']=="SUCCESS" && data['err_code']=="USERPAYING"){
                                //支付失败
                            $('#code').hide();
                            $("#pay_status").html("用户支付中，等待输入密码！")                            
                            var querytime = setInterval(()=>{
                                $.ajax({
                                    url: '/school/admin_order/ajax_query_micro_order',          
                                    data: {
                                        order_no: "{$orderData.order_no}"                               
                                    },  
                                    success:(data)=>{        
                                                                       
                                        data = JSON.parse(data)                                                                                     
                                        if(data.trade_state=="SUCCESS"){ 
                                            clearInterval(querytime);                                       
                                            $("#pay_status").html("支付成功！") 
                                        }else  if(data.trade_state=="USERPAYING"){     
                                            $("#pay_status").html("用户支付中，等待输入密码！") 
                                        }else  if(data.trade_state=="CLOSED"){      
                                            clearInterval(querytime);                                                                                  
                                            $("#pay_status").html("支付失败！支付已关闭！") 
                                        }else  if(data.trade_state=="REVOKED"){      
                                            clearInterval(querytime);                                                                                  
                                            $("#pay_status").html("支付失败！支付已撤消！") 
                                        }else  if(data.trade_state=="NOTPAY"){    
                                            clearInterval(querytime);                                                                                  
                                            $("#pay_status").html("支付失败！未支付！") 
                                        }else  if(data.trade_state=="PAYERROR"){      
                                            clearInterval(querytime);                                                                                  
                                            $("#pay_status").html("支付失败！未知原因！") 
                                        }
                                    }
                                })
                            },5000)
                        }else{
                            //支付失败
                            $('#code').hide();
                            $("#pay_status").html("支付失败！"+ "原因："+data['result_msg'])           
                        }
                    }
                })
            },2000)           
        }       
     },2000)
   })
</script>
</body>
</html>
